<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="js/script.js"></script>
<script type="text/javascript">
var HttPRequest = GetXmlHttpObject();

function doCallAjax(){
	
	var url = 'checkuser.php';
	var pmeters = "username=" + encodeURI( document.getElementById("txtUsername").value) +
					"&password=" + encodeURI( document.getElementById("txtPassword").value );

		HttPRequest.open('POST',url,true);

		HttPRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		HttPRequest.setRequestHeader("Content-length", pmeters.length);
		HttPRequest.setRequestHeader("Connection", "close");
		HttPRequest.send(pmeters);
		
		
		HttPRequest.onreadystatechange = function()
		{

			if(HttPRequest.readyState == 3)  // Loading Request
			{
				document.getElementById("mySpan").innerHTML = "Now is Loading...";
			}

			if(HttPRequest.readyState == 4)  // Return Request
			{	alert(HttPRequest.responseText);
				if(HttPRequest.responseText == 'false')
				{
					document.getElementById("mySpan").innerHTML = "<font color='red'><h1>คุณใส่ ข้อมูลไม่ถูกต้อง</font>";
				}
				else
				{
					document.getElementById("userlogin").innerHTML = HttPRequest.responseText;
				}
			}
			
		}

  }

function checkEnter(event){
	var key = event.keyCode;
	if(key == 13){
		alert("you pess Enter key");
	}
}
</script>
</head>
<body>

<?php 
    //หากมีการเข้าสู่ระบบแล้วไม่ต้องแสดง from login
    if ($sess_userid<>session_id() or $sess_username=="" or $sess_status<>"Active") {
		echo "<form name=\"frmMain\">
<span id=\"mySpan\"></span>
<table width=\"274\" border=\"0\">
<tr>
<th width=\"117\">
 <div align=\"left\">Username</div></th>
<td><input type=\"text\" name=\"txtUsername\" id=\"txtUsername\" size=\"20\"></td>
<th width=\"117\">
 <div align=\"left\">Password</div></th>
<td><input type=\"password\" name=\"txtPassword\" id=\"txtPassword\" size=\"20\"></td>
<td><input name=\"btnLogin\" type=\"button\" id=\"btnLogin\" OnClick=\"JavaScript:doCallAjax();\" value=\"Login\"></td>
</tr>
</table>

</form>";
	}?>

</body>
</html>